package com.lix.controller.workflow;

import com.lix.base.BaseResult;
import com.lix.pojo.model.Leave;
import com.lix.pojo.model.Loan;
import com.lix.service.workflow.ILeaveService;
import com.lix.service.workflow.ILoanService;
import com.lix.vo.workflow.req.LeaveReq;
import com.lix.vo.workflow.req.LoanReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("业务申请表单控制器")
@ResponseBody
@RestController
@RequestMapping("/flow")
public class BusinessFormController {

    @Autowired
    private ILeaveService leaveService;

    @Autowired
    private ILoanService loanService;

    @PostMapping("/leave/add")
    @ApiOperation("新增请假申请")
    public BaseResult addLeave(@RequestBody Leave leave) {
        return leaveService.add(leave);
    }

    @PostMapping("/leave/list")
    @ApiOperation("条件分页查询请假申请列表数据")
    public BaseResult listPageLeave(@RequestBody LeaveReq req) {
        return leaveService.listPage(req);
    }

    @ApiOperation("查询请假详情信息")
    @GetMapping("/leave/view/{id}")
    public BaseResult viewLeave(@PathVariable String id) {
        Leave leave = leaveService.getById(id);
        return BaseResult.ok(leave);
    }

    @ApiOperation("更新请假详情信息")
    @PostMapping("/leave/edit")
    public BaseResult editLeave(@RequestBody Leave leave) {
        return leaveService.update(leave);
    }


    @ApiOperation("新增借款申请")
    @PostMapping("/loan/add")
    public BaseResult addLoan(@RequestBody Loan loan) {
        return loanService.add(loan);
    }

    @ApiOperation("条件分页查询借款申请列表数据")
    @PostMapping("/loan/list")
    public BaseResult listPageLoan(@RequestBody LoanReq req) {
        return loanService.listPage(req);
    }

    @ApiOperation("查询借款详情信息")
    @GetMapping("/loan/view/{id}")
    public BaseResult viewLoan(@PathVariable String id) {
        Loan loan = loanService.getById(id);
        return BaseResult.ok(loan);
    }

    @ApiOperation("修改借款详情信息")
    @GetMapping("/loan/edit")
    public BaseResult editLoan(@RequestBody Loan loan) {
        return loanService.update(loan);
    }

}
